﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace Bundler.MvcExample
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );

            var cssOptions = new BundleOptions { IncludeFileExtensionInAlias = true, EnableOptimizations = true };
            var css = new Bundle("~/css", typeof(CssMinify), cssOptions);
            css.AddFile("~/Content/Site.css");
            css.AddFile("~/Content/themes/base/jquery-ui.css");
            css.AddContent(".special { display: block; background-color: #000; color: #a7f707; font-family: Consolas; font-size: 11pt; padding: 10px; margin: 10px;}");
            BundleTable.Add(css);

            var printCssOptions = new BundleOptions { IncludeFileExtensionInAlias = true, EnableOptimizations = true, Css = new CssOptions { Media = "print" } };
            var printCss = new Bundle("~/printCss", typeof(CssMinify), printCssOptions);
            printCss.AddFile("~/Content/Print.css");
            printCss.AddContent(".whitebg { background-color: #000; }");
            BundleTable.Add(printCss);

            var spriteOptions = new BundleOptions { IncludeFileExtensionInAlias = true, EnableOptimizations = true };
            var spriteCss = new Bundle("~/sprite", typeof(CssMinifySpriteEmbed), spriteOptions);
            spriteCss.AddFile("~/Content/Sprite.css");
            BundleTable.Add(spriteCss);

            var js = new Bundle("~/js", typeof(JsMinify));
            js.AddFile("~/Scripts/jquery-1.8.2.min.js");
            js.AddFile("~/Scripts/jquery-ui-1.8.23.min.js");
            js.AddFile("~/Scripts/modernizr-2.6.2.js");
            js.AddContent("$(function() { $('.special').click(function(e){e.preventDefault();alert('You got it!');}); });");
            BundleTable.Add(js);
        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }
    }
}